package com.xbongbong.saas.enums.dictionary;

import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.Objects;

/**
 * 需特殊设置的数据字典
 * 创建时间 2019/6/10 2:15 PM
 * 修改时间 2019/6/10 2:15 PM
 * @author chy
 * @since v1.0
 * @version v1.0
 */
@Getter
public enum DictionarySpecialEnum {
    /*
      ---------------------------------------------------------------------------
      该部分为公司级别数据字典，即不与formId（表单id）关联
      ---------------------------------------------------------------------------
     */
    /**
     * 客户状态
     */
    CUSTOMER_STATUS(DictionaryEnum.CUSTOMER_STATUS, XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),
    /**
     * 合同状态
     */
    CONTRACT_STATUS(DictionaryEnum.CONTRACT_STATUS, XbbRefTypeEnum.CONTRACT.getCode()),

    /**
     * 延期原因
     */
    DELAY_CAUSE(DictionaryEnum.DELAY_CAUSE, XbbRefTypeEnum.COMMUNICATE_PLAN.getCode()),

    /**
     * 客户阶段
     */
    CUSTOMER_STAGE(DictionaryEnum.CUSTOMER_STAGE, XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),
    CUSTOMER_STAGE_WASTAGE(DictionaryEnum.CUSTOMER_STAGE_WASTAGE, XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),

    /**
     * 物流公司
     */
    EXPRESS_NAME(DictionaryEnum.EXPRESS_NAME, XbbRefTypeEnum.CONTRACT.getCode()),

    EXPRESS_NAME_CONTRACT_OUTSTOCKTOCK(DictionaryEnum.EXPRESS_NAME, XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode()),
    EXPRESS_NAME_RETURNED_PURCHASE_OUTSTOCK(DictionaryEnum.EXPRESS_NAME, XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode()),
    EXPRESS_NAME_OTHER_OUTSTOCK(DictionaryEnum.EXPRESS_NAME, XbbRefTypeEnum.OTHER_OUTSTOCK.getCode()),
    EXPRESS_NAME_PRODUCTION_MATERIEL_OUTSTOCK(DictionaryEnum.EXPRESS_NAME, XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode()),
    EXPRESS_NAME_WORK_ORDER_OUTSTOCK(DictionaryEnum.EXPRESS_NAME, XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getCode()),
    EXPRESS_NAME_ORDER_OUTSTOCK(DictionaryEnum.EXPRESS_NAME, XbbRefTypeEnum.ORDER_OUTSTOCK.getCode()),

    /**
     * 销售阶段
     */
    SALE_STAGE(DictionaryEnum.SALE_STAGE, XbbRefTypeEnum.SALES_OPPORTUNITY.getCode()),
    SALE_STAGE_WASTAGE(DictionaryEnum.SALE_STAGE_WASTAGE, XbbRefTypeEnum.SALES_OPPORTUNITY.getCode()),

    /**
     * 线索阶段
     */
    CLUE_STAGE(DictionaryEnum.CLUE_STAGE, XbbRefTypeEnum.CLUE.getCode()),
    CLUE_STAGE_INVALID(DictionaryEnum.CLUE_STAGE_INVALID, XbbRefTypeEnum.CLUE.getCode()),

    /**
     * 未知
     */
    UNKNOWN(DictionaryEnum.UNKNOWN, 404),
    ;

    private DictionaryEnum dictionaryEnum;

    private Integer businessType;


    DictionarySpecialEnum(DictionaryEnum dictionaryEnum, Integer businessType) {
        this.dictionaryEnum = dictionaryEnum;
        this.businessType = businessType;
    }

    /**
     * 根据code获取数据字典枚举
     * @param businessType 业务类型
     * @param attr 字段
     * @return com.xbongbong.saas.enums.dictionary.DictionaryEnum
     * @author zcp
     * @date 2019/3/4 15:14
     * @since v1.0
     * @version v1.0
     */
    public static DictionarySpecialEnum getEnum(Integer businessType, String attr) {
        for (DictionarySpecialEnum cache : values()) {
            Integer thisBusinessType = cache.getBusinessType();
            String thisAttr = cache.getDictionaryEnum().getSaasAttr();
            if (Objects.equals(businessType, thisBusinessType) && Objects.equals(attr, thisAttr)) {
                return cache;
            }
        }
        return UNKNOWN;
    }

}
